package cn.lds.healthj377.exception;

import cn.lds.healthj377.dto.DsHealthConstant;
import cn.lds.healthj377.dto.ResponseDTO;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SysExceptionResolve implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {

        SysException sysException = null;
        //控制台显示异常
        e.printStackTrace();

        if (e instanceof SysException){
            sysException = (SysException) e;
        }else {
            sysException = new SysException(ResponseDTO.buildError(DsHealthConstant.SysMsg.SYS_MSG));
        }

        ModelAndView mv = new ModelAndView();
        mv.addObject("exceptionErr",sysException.getResponseDTO());
        mv.setViewName("error");

        return mv;
    }
}
